# https://gitee.com/yueyinqiu5990/tj12413601/blob/master/assignment1/question5/main_calculation_on_sin_good.py
#
# 相比于 main_calculation_on_sin_bad.py ，
# 这里我们在两个周期上采样，并且间隔着舍去为零的项，
# 发现会得到正确的结果。
#
# （后发现其实只要直接 0 到 2 pi 采样即可）
#
import math

import matplotlib.pyplot
import torch

import main_calculation

order = 100

period = 2 * math.pi
limit3 = period
limit1 = -limit3
x_tensor = torch.linspace(limit1, limit3, order)
y_tensor = torch.tensor([math.sin(float(x)) for x in x_tensor])
result = torch.fft.fft(y_tensor)
d = {}
for i, f in enumerate(result[::2]):
    d[i] = complex(f) / order

matplotlib.pyplot.axvspan(-math.pi, math.pi, alpha=0.1)
# noinspection PyProtectedMember
main_calculation._draw_from_dictionary_of_a(d, p=2 * math.pi)
matplotlib.pyplot.show()
